/**
 * Created by Yun on 2016-03-13.
 */

function wrapOnEnter(onEnter) {
  return function(nextState, replace, callback) {
    Promise.resolve(onEnter(nextState, replace)).then(callback);
  };
}

export default function router(path) {
  return function (target, property, descriptor){
    target.route = {
      path,
      component: target,
      onEnter: target.onEnter && wrapOnEnter(target.onEnter),
      childRoutes: target.childRoutes && target.childRoutes.map(v=>v.route || v),
      indexRoute: target.indexRoute && (target.indexRoute.route || target.indexRoute),
    };
  }
}
